import 'package:boss/ui/page/commodity/pickerCategories/picker_commodity_provider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

import 'categories_commodity_item.dart';

class CategoriesCommodityList extends StatelessWidget {
  final ItemScrollController scrollController;

  const CategoriesCommodityList({Key key, this.scrollController}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Consumer<PickerCommodityProvider>(
        builder: (context, provider, child) {
          return ScrollablePositionedList.builder(
            itemScrollController: scrollController,
            padding: EdgeInsets.only(bottom: 50),
            itemBuilder: (context, index) {
              var current = provider.currentCommoditys[index];

              return CategoriesCommodityItem(
                data: current,
                index: index,
                isShowSku: provider.isShowSku,
                type: provider.type,
                onTap: () {
                  if (provider.type == 0) {
                    provider.toggleCommoditySelected(current);
                  }
                },
                onNumberChanged: (value) {
                  provider.setCommodityCount(current, value);
                },
              );
            },
            itemCount: provider.currentCommoditys.length,
          );
        },
      ),
    );
  }
}
